package com.nuoniu.sibanyun.mapper.production;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.annotation.DataAuth;
import com.nuoniu.sibanyun.entity.dto.ProductionWorkSearchDto;
import com.nuoniu.sibanyun.entity.dto.VProductionWorkMainSearchDto;
import com.nuoniu.sibanyun.entity.dto.statistics.ProductionWorkCumSummaryDto;
import com.nuoniu.sibanyun.entity.dto.statistics.ProductionWorkInAndPickDto;
import com.nuoniu.sibanyun.entity.dto.statistics.ProductionWorkMonthSummaryDto;
import com.nuoniu.sibanyun.entity.production.VProductionWorkMain;
import com.nuoniu.sibanyun.entity.vo.UnFinishInventoryDetailVo;
import com.nuoniu.sibanyun.entity.vo.UnFinishProductionWorkVo;
import com.nuoniu.sibanyun.entity.vo.reportVo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 生产加工单 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2021-03-13
 */
public interface VProductionWorkMainMapper extends BaseMapper<VProductionWorkMain> {

    @Select("select voucher_code from ma_written_instruction where company_id=#{companyId} and date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) and data_source = #{dataSource} order by create_date desc limit 1 ")
    String getNewestCode(Integer companyId, String dateStr,String dataSource);


    @DataAuth(tableAlias = "wm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<VProductionWorkMain> listNotFinishMain(Integer companyId,Integer accountId,@Param("dto") VProductionWorkMainSearchDto productionWorkMainSearchDto);

    @DataAuth(tableAlias = "wm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<VProductionWorkMain> listNotFinishMain2(Integer companyId,Integer accountId,@Param("dto") VProductionWorkMainSearchDto productionWorkMainSearchDto);
    /**
     * 获取某个加工单（所有产品明细的）累计派遣数量
     * @param id
     * @return
     */
    BigDecimal getAllDetailCumDispatchQuantity(Integer companyId,Integer accountId,Long id);



    /**********************        委外加工单 领料          ************************/

    /**
     * 获取 未完工 的 委外加工单（领料 使用）
     * @param companyId
     * @param accountId
     * @param delegateProductionWorkSearchDto
     * @return
     */
    List<UnFinishProductionWorkVo> listUnFinishProductionWorkVo(Integer companyId, Integer accountId, @Param("dto") ProductionWorkSearchDto delegateProductionWorkSearchDto);

    /**
     * 获取 未完工 的材料明细（领料 使用）
     * @param companyId
     * @param accountId
     * @param delegateProductionWorkSearchDto
     * @return
     */
    List<UnFinishInventoryDetailVo> listUnFinishInventoryDetailVo(Integer companyId, Integer accountId, @Param("dto") ProductionWorkSearchDto delegateProductionWorkSearchDto);




    /**********************        生产制造 统计报表  2022-06-14        ************************/


    /**
     * 生产订单执行汇总表
     * @param page
     * @param dto
     * @return
     */
    Page<ProductionWorkCumSummaryVo> pageProductionWorkCumSummaryVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);

    /**
     * 生产订单执行明细表
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionWorkCumDetailVo> pageProductionWorkCumDetailVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);

    /**
     * 生产订单领料汇总表
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionPickReturnCumSummaryVo> pageProductionPickReturnCumSummaryVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);

    /**
     * 生产订单领料明细表
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionPickReturnCumDetailVo> pageProductionPickReturnCumDetailVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);


    /**
     * 生产领料异常表
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionPickAbnormalVo> pageProductionPickAbnormalVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);

    /**
     * 生产领料差异汇总表
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionPickAbnormalVo> pageProductionPickAbnormalSumVo(Page page,Integer companyId, @Param("dto")ProductionWorkCumSummaryDto dto);

    /**
     * 生产入库月报表
     * @param page
     * @param companyId
     * @param productionWorkMonthSummaryDto
     * @return
     */
    Page<ProductionMonthInVo> pageProductionMonthInVo(Page page, Integer companyId, @Param("dto")ProductionWorkMonthSummaryDto productionWorkMonthSummaryDto);

    /**
     * 生产领料月报表  0.领料 5.退料  cumPickQuantity(领料套数)  cumRetQuantity(退料套数)
     * @param page
     * @param companyId
     * @param productionWorkMonthSummaryDto
     * @return
     */
    Page<ProductionPickReturnMonthSummaryVo> pageProductionPickReturnMonthSummaryVo(Page page, Integer companyId, @Param("dto")ProductionWorkMonthSummaryDto productionWorkMonthSummaryDto);

    /**
     * 生产入库领料查询 -- 产品入库情况
     * @param page
     * @param companyId
     * @param dto
     * @return
     */
    Page<ProductionInMainVo> pageProductionInMainVo(Page page, Integer companyId, @Param("dto") ProductionWorkInAndPickDto dto);

    /**
     * 生产入库领料查询 -- 对应产品领料情况
     * @param companyId
     * @param dto
     * @return
     */
    List<ProductionPickVo> listProductionPickVo(Integer companyId, @Param("dto") ProductionWorkInAndPickDto dto);

}
